<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        p {
            color: rgb(165, 210, 31);
            font-size: large;
        }

        div {
            width: 520px;
            height: 50px;
            background-color: antiquewhite;
        }
    </style>
</head>

<body>
    <button>显示现在时间</button>
    <div>现在</div>
    <div id="one">1</div>
    <a href="https://www.bilibili.com/video/BV1Sy4y1C7ha?p=202&vd_source=480c28921b1b6c12cb33e4a6f0a94947">课程视频</a>
    <script>
        //  https://www.bilibili.com/video/BV1Sy4y1C7ha?p=202&vd_source=480c28921b1b6c12cb33e4a6f0a94947
        //点击button按钮，显示当前时间
        let btn = document.querySelector("button");
        let div = document.querySelector("div");
        btn.onclick = function () {
            div.innerHTML = getDate();
            //div.getDate();
        }
        function getDate() {
            let date = new Date();
            let years = date.getFullYear();
            let month = date.getMonth();
            let day = date.getDay();
            let hour = date.getHours();
            let minutes = date.getMinutes();
            let second = date.getSeconds();
            return "现在时间是" + years + "年" + month + "月" + day + "日" + hour + "时" + minutes + "分" + second + "秒";

        }
        //不添加事件，刷新即改变
        var div1 = document.getElementById('one');
        div1.innerHTML = getDate();
    </script>

</body>

</html>